﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Grain.Crm.DataMigrator.CrmServices;

namespace Grain.Crm.DataMigrator.Imports
{
    public class ContactImport : ImportBase
    {
        public ContactImport(CrmService service, WhoAmIResponse whoAmIresponse, ImportPayload importPayload)
            : base(service, whoAmIresponse, importPayload)
        {
        }

        protected override void Preprocess(out bool entityExists)
        {

            ImportsGlobal.Contact = FileContent.GetByHeading(HeaderRow, "First Name") + " " +
                                    FileContent.GetByHeading(HeaderRow, "Last Name");

            var contactId = ImportsHelper.GetEntityId(_service, ThisEntityName, new string[] { "fullname" }, new string[] { ImportsGlobal.Contact });

            if (contactId != null)
            {
                entityExists = true;

                ImportsHelper.AddKeyValueToContent(contactId.GetValueOrDefault(), ThisEntityName, ref HeaderRow, ref FileContent);
            }
            else
                entityExists = false;


        }

        protected override void Postprocess()
        {

        }
    }
}
